package cn.edu.xmu.oomall.customer.mapper.jpa;

import cn.edu.xmu.oomall.customer.mapper.po.CustomerPo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * @author 谢传艳
 * @date 2024/12/18
 */
@Repository
public interface CustomerPoMapper extends JpaRepository<CustomerPo, Long> {
    Optional<CustomerPo> findByUserName(String userName);

    Optional<CustomerPo> findByMobile(String mobile);

    @Query("SELECT c FROM CustomerPo c WHERE " +
            "(:userName IS NULL OR c.userName LIKE %:userName%) AND " +
            "(:name IS NULL OR c.name LIKE %:name%) AND " +
            "(:mobile IS NULL OR c.mobile LIKE %:mobile%)")
    Page<CustomerPo> findByUserNameAndNameAndMobile(@Param("userName") String userName,
                                                    @Param("name") String name,
                                                    @Param("mobile") String mobile,
                                                    Pageable pageable);
}
